package book_management.book;

import java.util.ArrayList;
import java.util.List;

/**
 * 书架类 - 存放一本本具体的图书，程序操作的是书架类
 **/
public class BookList {
    // books存放了所有当前书架中的书，每个Book对象就是一本书的实体
    private static List<Book> books = new ArrayList<>();
    // booksName存放了所有的书本名称 - 查询书籍等都是通过书名来操作
    private static List<String> booksName = new ArrayList<>();

    // 初始化books和booksName,默认将四大名著放入书架中
    // 使用static代码块初始化static变量
    static {
        books.add(new Book("三国演义","罗贯中",66.6,"小说"));
        books.add(new Book("红楼梦","曹雪芹",88.8,"小说"));
        books.add(new Book("水浒传","施耐庵",55.6,"小说"));
        books.add(new Book("西游记","吴承恩",88.6,"小说"));

        booksName.add("三国演义");
        booksName.add("红楼梦");
        booksName.add("水浒传");
        booksName.add("西游记");
    }

    public void displayBooks() {
        // 遍历所有书本，打印即可
        for (Book book : books) {
            System.out.println(book);
        }
    }

    public boolean contains(String booksName) {

        return BookList.booksName.contains(booksName);
    }

    public void add(Book book) {
        books.add(book);
        booksName.add(book.getBookName());
    }
}